package com.shirley.pers.zhufengfmvi.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.shirley.pers.zhufengfmvi.fragments.BaseFragment;

import java.util.List;

/**
 * Description: 通用的ViewPager数据适配器<br/>
 * <p/>
 * Copyright (c) , 2016, Shirley Xian <br/>
 * This program is protected by copyright laws. <br/>
 * ClassName: CommonPagerAdapter<br/>
 * Date: 2016/4/6 9:19
 *
 * @author Shirley Xian
 * @version 1.0
 */
public class CommonPagerAdapter extends FragmentPagerAdapter {
    private List<BaseFragment> mFragments;

    public CommonPagerAdapter(FragmentManager fm, List<BaseFragment> fragments) {
        super(fm);
        mFragments = fragments;
    }
    /**
     * Return the Fragment associated with a specified position.
     *
     * @param position
     */
    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    /**
     * Return the number of views available.
     */
    @Override
    public int getCount() {
        int count = 0;
        if (mFragments != null) {
            count = mFragments.size();
        }
        return count;
    }
    /**
     * This method may be called by the ViewPager to obtain a title string
     * to describe the specified page. This method may return null
     * indicating no title for this page. The default implementation returns
     * null.
     *
     * @param position The position of the title requested
     * @return A title for the requested page
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return mFragments.get(position).getFragmentTitle();
    }
}
